Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, 
        "d+": this.getDate(), 
        "H+": this.getHours(),  
        "m+": this.getMinutes(),  
        "s+": this.getSeconds(), 
        "q+": Math.floor((this.getMonth() + 3) / 3), 
        "S": this.getMilliseconds()  
    };
    var year = this.getFullYear();
    var yearstr = year + '';
    yearstr = yearstr.length >= 4 ? yearstr : '0000'.substr(0, 4 - yearstr.length) + yearstr;
    
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (yearstr + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

$(function(){
    // var api = "/api";
    var api = "";
    var App = {
        init: function(){
            // dom初始化
            this.initDom();
            // 数据初始化
            this.data = false;
            this.mapData = false;
            this.time = 5000;
            this.initData();
        },
        initDom: function(){
            var self = this;
            // self.scale = 1366/1920;
            self.scale = document.body.offsetWidth/1920;
            $('.datavLayout').css({
                height: (document.body.offsetWidth*9/16)+'px'
            })
            document.getElementById('style').innerHTML = template('cssTemp', {
                scale: self.scale
            });
            $('.datavLayout').show();
        },
        initAuto: function(){
            var self = this;
            var time = $('.time');
            setInterval(function(){
                time.html((new Date()).Format('yyyy年MM月dd日   HH:mm:ss'));
            }, 1000);
            // setInterval(function(){
            //     self.ajax(api + '/datav/area2', {
            //         data: {
            //            "divisionCode": 630000
            //         },
            //         success: function(result){
            //             if(result.status){
            //                 self.data = result.data;
            //                 $('.grantTotal').html(self.toThousands(self.data.grantTotal));
            //                 $('.grantMoney').html(self.toThousands(self.data.grantMoney));
            //             }
            //         },
            //         error: function(error){
            //             console.log(error);
            //         }
            //     }
            // );
            // }, 30000);
        },
        initData: function(){
            var self = this;
            this.ajax(api + '/datav/area2', {
                    data: {
                       "divisionCode": 630100
                    },
                    success: function(result){
                        if(result.status){
                            $('.datavLayout > div').show();
                            self.data = result.data;
                            // $('.grantTotal').html(self.toThousands(self.data.grantTotal));
                            // $('.grantMoney').html(self.toThousands(self.data.grantMoney));
                            // self.ltWordCloud();
                            self.qhMapTj();
                            self.qhMap();
                            // self.lbPie();
                            // self.cbPie();
                            // self.rbPie();
                            self.initAuto();
                            self.areaYearData();
                            self.categoryYearData();
                        }
                    },
                    error: function(error){
                        console.log(error);
                    }
                }
            );
            $.getJSON(api + '/resources/assets/map/630100.json', function(data){
                self.mapData = data;
                self.qhMap();
            });
        },
        numFormat: function(value){
            if(value>=100000000){
                return (value/100000000).toFixed(2)+'亿'
            }else if(value>=10000){
                return (value/10000).toFixed(2)+'万'
            }else{
                return value
            }
        },
        areaYearData: function(){
            var self = this;
            var option = {
                color: ['#50a3cc',
                        '#cddc39',
                        '#ffc107',
                        '#8bc34a',
                        '#00bcd4'],
                tooltip : {
                    trigger: 'axis',
                    axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                        type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                legend: {
                    data: [],
                    left: 'right',
                    textStyle: {
                        color: '#fff',
                        fontSize: self.scale*24
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis:  {
                    type: 'value',
                    axisLine: {
                      lineStyle: {
                        color: '#fff'
                      }
                    },
                    axisLabel: {
                        formatter: function (value, index) {
                          if(value>=100000000){
                            return parseInt(value/100000000)+'亿'
                          }else if(value>=10000){
                            return parseInt(value/10000)+'万'
                          }else{
                            return value
                          }
                        }
                    },
                    splitLine: {
                        lineStyle: {
                            color: "rgba(255,255,255,.1)",
                            show: false
                        }
                    }
                },
                yAxis: {
                    type: 'category',
                    data: [],
                    axisLabel: {
                        textStyle: {
                            fontSize: self.scale*20
                        }
                    },
                    axisLine: {
                      lineStyle: {
                        color: '#fff'
                      }
                    },
                    splitLine: {
                        lineStyle: {
                            color: "rgba(255,255,255,.1)",
                            show: false
                        }
                    }
                },
                series: []
            };

            if(self.data.areaYearData&&self.data.areaYearData.length > 0){
                var thisObj = self.data.areaYearData[0].pointList;
                for (var i = 0; i < thisObj.length; i++) {
                    option.yAxis.data.push(thisObj[i].x);
                }
                for (var i = 0; i < self.data.areaYearData.length; i++) {
                    var thisObj = self.data.areaYearData[i];
                    option.legend.data.push(thisObj.name);
                    var barData = [];
                    for (var j = 0; j < thisObj.pointList.length; j++) {
                        barData.push(thisObj.pointList[j].y);
                    }
                    option.series.push({
                        name: thisObj.name,
                        type: 'bar',
                        stack: '总量',
                        label: {
                            normal: {
                                show: false,
                                position: 'insideLeft'
                            }
                        },
                        data: barData
                    });
                }
                var chart = echarts.init($('.rb-pie')[0]);
                chart.setOption(option);
            }
        },
        categoryYearData: function(){
            var self = this;
            var option = {
                title : {
                    text: '',
                    x:'center',
                    textStyle: {
                        color: '#fff'
                    }
                },
                grid: {
                    containLabel: true
                },
                color: ['#8bc34a',
                        '#50a3cc',
                        '#cddc39',
                        '#ffc107',
                        '#00bcd4'],
                tooltip : {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                series : [
                    {
                        name: '',
                        type: 'pie',
                        radius: ['0%', '60%'],
                        center: ['50%', '54%'],
                        data:[],
                        label: {
                            normal: {
                                formatter: '{b}\n{d}%',
                                textStyle: {
                                    fontSize: 20*self.scale
                                }
                            }
                        },
                        itemStyle: {
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            var chart = echarts.init($('.lb-map .lb-pie')[0]);
            
            var currentIndex = -1;
            var changeFun = function(){
                currentIndex++;
                if(currentIndex == self.data.categoryYearData.length){
                    currentIndex = 0;
                }
                option.series[0].data = [];
                var thisObj = self.data.categoryYearData[currentIndex];
                option.title.text = thisObj.name;
                option.series[0].name = thisObj.name;
                for (var i = 0; i < thisObj.pointList.length; i++) {
                    option.series[0].data.push({
                        value:thisObj.pointList[i].y,
                        name: thisObj.pointList[i].x
                    });
                }
                chart.setOption(option);
            }
            changeFun();
            setInterval(function () {
                changeFun()
            }, self.time);
        },
        // 左上角热词
        ltWordCloud: function(){
            var self = this;
            var option = {
                color: ['#50a3cc',
                        '#2095a5',
                        '#4acab4',
                        '#8bc34a',
                        '#ffc107',
                        '#cddc39',
                        '#00bcd4'],
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)"
                },
                series: [
                    {
                        name:'项目分类',
                        type:'pie',
                        selectedMode: 'single',
                        radius: [0, '30%'],

                        label: {
                            normal: {
                                position: 'inner'
                            }
                        },
                        labelLine: {
                            normal: {
                                show: false
                            }
                        },
                        itemStyle: {
                            normal: {
                                opacity: .8
                            },
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        },
                        data:[]
                    },
                    {
                        name:'项目',
                        type:'pie',
                        radius: ['40%', '55%'],
                        itemStyle: {
                            normal: {
                                opacity: .8
                            },
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        },
                        data:[]
                    }
                ]
            };
            option.series[0].data = [];
            option.series[1].data = [];
            for (var i = 0; i < self.data.projectRank.length; i++) {
                var t = self.data.projectRank[i];
                option.series[0].data.push({
                    name: t.name,
                    value: t.y,
                });
                if(t.pointList&&t.pointList.length>0){
                    for (var j = 0; j < t.pointList.length; j++) {
                        var h = t.pointList[j];
                        option.series[1].data.push({
                            name: h.x,
                            value: h.y,
                        });
                    }
                }
            }
            var chart = echarts.init($('.lt-map .lt-word')[0]);
            chart.setOption(option);

            var currentIndex = 0;
            var dataLen = option.series[1].data.length;
            var changeFun = function(){
                // 取消之前高亮的图形
                chart.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 1,
                    dataIndex: currentIndex
                });
                currentIndex = (currentIndex + 1) % dataLen;
                // 高亮当前图形
                chart.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 1,
                    dataIndex: currentIndex
                });
                // 显示 tooltip
                chart.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 1,
                    dataIndex: currentIndex
                });
            }
            changeFun();
            setInterval(function () {
                changeFun()
            }, self.time);
        },
        // 地图
        qhMapTj: function(){
            var self = this;
            self.areaData = {
                "grantTotal": 0,
                "areaStr": "西宁市",
                "projectNum": 0,
                "registerBatchNum": 0,
                "grantCount": 0,
                "grantMoney": 0,
                "categoryDataForArea": [
                  {
                    "name": "人次",
                    "y": "",
                    "pointList": []
                  },
                  {
                    "name": "金额",
                    "y": "",
                    "pointList": []
                  }
                ]
            }
            for (var i = 0; i < self.data.areaData.length; i++) {
                var thisObj = self.data.areaData[i];
                thisObj.grantTotal&&(self.areaData.grantTotal += thisObj.grantTotal);
                thisObj.projectNum&&(self.areaData.projectNum += thisObj.projectNum);
                thisObj.registerBatchNum&&(self.areaData.registerBatchNum += thisObj.registerBatchNum);
                thisObj.grantCount&&(self.areaData.grantCount += thisObj.grantCount);
                thisObj.grantMoney&&(self.areaData.grantMoney += thisObj.grantMoney);
                if(thisObj.categoryDataForArea&&thisObj.categoryDataForArea.length == 2){
                    for (var j = 0; j < 2; j++) {
                        var categoryData = thisObj.categoryDataForArea[j];
                        var thisCategoryData = self.areaData.categoryDataForArea[j];
                        for (var k = 0; k < categoryData.pointList.length; k++) {
                            var hhh = categoryData.pointList[k];
                            var find = false;
                            for (var m = 0; m < thisCategoryData.pointList.length; m++) {
                                if(thisCategoryData.pointList[m].x == hhh.x){
                                    thisCategoryData.pointList[m].y += hhh.y;
                                    find = true;
                                }
                            }
                            if(!find){
                                thisCategoryData.pointList.push({
                                    x: hhh.x,
                                    y: hhh.y
                                });
                            }
                        }
                    }
                }
            }
            // console.log(self.areaData);
        },
        qhMap: function(){
            var self = this;
            var option = {
                tooltip: {
                    trigger: 'item',
                    formatter: '{b}',
                    backgroundColor: 'rgba(89,235,232,.5)',
                    textStyle: {
                        color: 'rgb(251, 243, 32)',
                        fontSize: self.scale*24
                    }
                },
                series : [{
                    name: 'iphone3',
                    type: 'map',
                    mapType: 'xxxxxxxx',
                    roam: false,
                    itemStyle: {
                        normal: {
                            areaColor: 'rgba(50,60,72,.3)',
                            borderColor: '#fff'
                        },
                        emphasis: {
                            areaColor: 'rgba(175,210,239,.5)',
                        }
                    },
                    label: {
                        emphasis: {
                            show: false
                        }
                    },
                    data:[]
                }]
            };
            if(self.data&&self.mapData){
                echarts.registerMap('xxxxxxxx', self.mapData);
                var chart = echarts.init($('.xn-map')[0]);
                chart.setOption(option);

                $('.xn-map').append('<div style="position:absolute;left:0;top:0;width:100%;height:100%;z-index:100"></div>');
                $('.xn-map').append('<div class="tip"></div>');

                var dataLen = self.mapData.features.length;
                var currentIndex = dataLen - 1;
                var changeFun = function(){
                    // 取消之前高亮的图形
                    chart.dispatchAction({
                        type: 'downplay',
                        seriesIndex: 0,
                        dataIndex: currentIndex
                    });
                    chart.dispatchAction({
                        type: 'hideTip',
                        seriesIndex: 0,
                        dataIndex: currentIndex
                    });
                    currentIndex++;
                    currentIndex = currentIndex>dataLen?0:currentIndex;
                    // 高亮当前图形
                    chart.dispatchAction({
                        type: 'highlight',
                        seriesIndex: 0,
                        dataIndex: currentIndex==dataLen?-1:currentIndex
                    });
                    // 显示 tooltip
                    chart.dispatchAction({
                        type: 'showTip',
                        seriesIndex: 0,
                        dataIndex: currentIndex==dataLen?-1:currentIndex
                    });
                    var selectedData = false;
                    if(currentIndex == dataLen){
                        selectedData = self.areaData;
                        $('.xn-map .tip').html(selectedData.areaStr).show();
                    }else{
                        $('.xn-map .tip').hide();
                        for (var i = 0; i < self.data.areaData.length; i++) {
                            if(self.data.areaData[i].divisionCode == self.mapData.features[currentIndex].id){
                                selectedData = self.data.areaData[i]
                            }
                        }
                    }
                    if(selectedData){
                        $('.num1').html(self.numFormat(selectedData.projectNum)||0);
                        $('.num2').html(self.numFormat(selectedData.registerBatchNum)||0);
                        $('.num3').html(self.numFormat(selectedData.grantTotal)||0);
                        $('.num4').html(self.numFormat(selectedData.grantMoney)||0);
                        $('.num5').html(self.numFormat(selectedData.grantCount)||0);
                        $('.xn-map-data .title').html(selectedData.areaStr+'当前资金发放情况');
                        $('.lt-map .title').html(selectedData.areaStr+'当前民生资金类别发放情况');
                        self.mapAuto(selectedData.categoryDataForArea);
                    }
                }
                changeFun();
                setInterval(function () {
                    changeFun();
                }, self.time);
            }
        },
        mapAuto: function(arr){
            var self = this;
            if(!arr){
                arr = [];
            }
            var option = {
                tooltip: {
                    trigger: 'axis'
                },
                grid: {
                    containLabel: true
                },
                color: ['rgba(89,235,232,.5)', '#fbf320'],
                xAxis: [
                    {
                        type: 'category',
                        data: [],
                        axisLine: {
                          lineStyle: {
                            color: '#fff'
                          }
                        },
                        nameTextStyle: {
                            fontSize: 16
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: '人次',
                        axisLabel: {
                            formatter: '{value}'
                        },
                        axisLine: {
                          lineStyle: {
                            color: '#fff'
                          }
                        },
                        axisLabel: {
                            formatter: function (value, index) {
                              if(value>=100000000){
                                return parseInt(value/100000000)+'亿'
                              }else if(value>=10000){
                                return parseInt(value/10000)+'万'
                              }else{
                                return value
                              }
                            }
                        },
                        splitLine: {
                            lineStyle: {
                                color: "rgba(255,255,255,.05)",
                                show: false
                            }
                        }
                    },
                    {
                        type: 'value',
                        name: '金额',
                        axisLabel: {
                            formatter: '{value}元'
                        },
                        axisLine: {
                          lineStyle: {
                            color: '#fff'
                          }
                        },
                        axisLabel: {
                            formatter: function (value, index) {
                              if(value>=100000000){
                                return parseInt(value/100000000)+'亿'
                              }else if(value>=10000){
                                return parseInt(value/10000)+'万'
                              }else{
                                return value
                              }
                            }
                        },
                        splitLine: {
                            lineStyle: {
                                color: "rgba(255,255,255,.1)",
                                show: false
                            }
                        }
                    }
                ],
                legend: {
                  data:["人次", "金额"],
                  left: 'center',
                  bottom: 20,
                  textStyle: {
                    color: '#fff'
                  }
                },
                series: [
                    {
                        name:'金额',
                        type:'bar',
                        data:[]
                    },
                    {
                        name:'人次',
                        type:'line',
                        smooth: true,
                        yAxisIndex: 1,
                        data:[]
                    }
                ]
            };
            option.xAxis[0].data = [];
            option.series[0].data = [];
            option.series[1].data = [];
            if(arr&&arr.length == 2){
                for (var i = 0; i < arr[0].pointList.length; i++) {
                    option.xAxis[0].data.push(arr[0].pointList[i].x);
                    option.series[0].data.push(arr[0].pointList[i].y);
                    option.series[1].data.push(arr[1].pointList[i].y);
                }
            }
            var chart = echarts.init($('.lt-map .lt-word')[0]);
            chart.setOption(option);

            // var currentIndex = 0;
            // var dataLen = self.data.monthData[0].pointList.length;
            // var changeFun = function(){
            //     // 取消之前高亮的图形
            //     chart.dispatchAction({
            //         type: 'downplay',
            //         seriesIndex: 0,
            //         dataIndex: currentIndex
            //     });
            //     currentIndex = (currentIndex + 1) % dataLen;
            //     // 高亮当前图形
            //     chart.dispatchAction({
            //         type: 'highlight',
            //         seriesIndex: 0,
            //         dataIndex: currentIndex
            //     });
            //     // 显示 tooltip
            //     chart.dispatchAction({
            //         type: 'showTip',
            //         seriesIndex: 0,
            //         dataIndex: currentIndex
            //     });
            // }
            // changeFun();
            // setInterval(function () {
            //     changeFun()
            // }, self.time);
        },
        // 左下角饼图
        lbPie: function(){
            var self = this;
            var option = {
                color: ['#8bc34a',
                        '#ffc107',
                        '#cddc39',
                        '#00bcd4',
                        '#50a3cc',
                        '#2095a5',
                        '#4acab4'],
                tooltip : {
                    trigger: 'item',
                    formatter: "{b} : {c} ({d}%)",
                    textStyle: {
                        // fontSize: '16px'
                    }
                },
                series : [
                    {
                        name: '',
                        type: 'pie',
                        radius: ['30%', '50%'],
                        center: ['50%', '50%'],
                        data:[],
                        itemStyle: {
                            normal: {
                                opacity: .8
                            },
                            emphasis: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            option.series[0].data = [];
            for (var i = 0; i < self.data.ageData[0].pointList.length; i++) {
                option.series[0].data.push({
                    value: self.data.ageData[0].pointList[i].y,
                    name: self.data.ageData[0].pointList[i].x
                });
            }
            var chart = echarts.init($('.lb-pie')[0]);
            chart.setOption(option);
            var currentIndex = 0;
            var dataLen = self.data.ageData[0].pointList.length;
            var changeFun = function(){
                // 取消之前高亮的图形
                chart.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                    dataIndex: currentIndex
                });
                currentIndex = (currentIndex + 1) % dataLen;
                // 高亮当前图形
                chart.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 0,
                    dataIndex: currentIndex
                });
                // 显示 tooltip
                chart.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: currentIndex
                });
            }
            changeFun();
            setInterval(function () {
                changeFun()
            }, self.time);
        },
        // 中下角折线柱状图
        cbPie: function(){
            var self = this;
            var option = {
                tooltip: {
                    trigger: 'axis'
                },
                color: ['rgba(89,235,232,.5)', '#fbf320'],
                xAxis: [
                    {
                        type: 'category',
                        data: [],
                        axisLine: {
                          lineStyle: {
                            color: '#fff'
                          }
                        },
                        nameTextStyle: {
                            fontSize: 16
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        name: '人次',
                        axisLabel: {
                            formatter: '{value}'
                        },
                        axisLine: {
                          lineStyle: {
                            color: '#fff'
                          }
                        },
                        axisLabel: {
                            formatter: function (value, index) {
                              if(value>=100000000){
                                return parseInt(value/100000000)+'亿'
                              }else if(value>=10000){
                                return parseInt(value/10000)+'万'
                              }else{
                                return value
                              }
                            }
                        },
                        splitLine: {
                            lineStyle: {
                                color: "rgba(255,255,255,.05)",
                                show: false
                            }
                        }
                    },
                    {
                        type: 'value',
                        name: '金额',
                        axisLabel: {
                            formatter: '{value}元'
                        },
                        axisLine: {
                          lineStyle: {
                            color: '#fff'
                          }
                        },
                        axisLabel: {
                            formatter: function (value, index) {
                              if(value>=100000000){
                                return parseInt(value/100000000)+'亿'
                              }else if(value>=10000){
                                return parseInt(value/10000)+'万'
                              }else{
                                return value
                              }
                            }
                        },
                        splitLine: {
                            lineStyle: {
                                color: "rgba(255,255,255,.1)",
                                show: false
                            }
                        }
                    }
                ],
                legend: {
                  data:["人次", "金额"],
                  left: 'center',
                  bottom: 20,
                  textStyle: {
                    color: '#fff'
                  }
                },
                series: [
                    {
                        name:'金额',
                        type:'bar',
                        data:[]
                    },
                    {
                        name:'人次',
                        type:'line',
                        smooth: true,
                        yAxisIndex: 1,
                        data:[]
                    }
                ]
            };
            option.xAxis[0].data = [];
            option.series[0].data = [];
            option.series[1].data = [];
            for (var i = 0; i < self.data.monthData[0].pointList.length; i++) {
                option.xAxis[0].data.push(self.data.monthData[0].pointList[i].x);
                option.series[0].data.push(self.data.monthData[0].pointList[i].y);
                option.series[1].data.push(self.data.monthData[1].pointList[i].y);
            }
            var chart = echarts.init($('.mb-bar')[0]);
            chart.setOption(option);

            var currentIndex = 0;
            var dataLen = self.data.monthData[0].pointList.length;
            var changeFun = function(){
                // 取消之前高亮的图形
                chart.dispatchAction({
                    type: 'downplay',
                    seriesIndex: 0,
                    dataIndex: currentIndex
                });
                currentIndex = (currentIndex + 1) % dataLen;
                // 高亮当前图形
                chart.dispatchAction({
                    type: 'highlight',
                    seriesIndex: 0,
                    dataIndex: currentIndex
                });
                // 显示 tooltip
                chart.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: currentIndex
                });
            }
            changeFun();
            setInterval(function () {
                changeFun()
            }, self.time);
        },
        // 右下角进度图
        rbPie: function(){
            var self = this;
            var man = parseInt(self.data.genderData[0].pointList[0].y*100/(self.data.genderData[0].pointList[0].y+self.data.genderData[0].pointList[1].y))
            $('.man .pa').css({
                height: man+'%'
            })
            $('.man .text').html(man);
            $('.woman .pa').css({
                height: (100-man)+'%'
            })
            $('.woman .text').html(100-man);
        },
        ajax: function(url, config){
            var self = this;
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'json',
                data: JSON.stringify(config.data||{}),
                contentType: 'application/json',
                success: function(data){
                    config.success(data);
                },
                error: function(error){
                    config.error();
                }
           });
        },
        toThousands: function(num){
            return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
        }
    }

    App.init();
})